# test.py

from pydicom.fileio.leanread import dicomfile

filename = "/Users/darcy/hg/repydicom/tests/testfiles/CT_small.dcm"
filename = "/Users/darcy/hg/repydicom/tests/testfiles/rtplan.dcm"


def val_repr(value):
    max_bytes_display = 60
    value = repr(value)
    if len(value) > max_bytes_display:
        format_str = "{shortval} ... # ({val_len} bytes)"
        value = format_str.format(shortval=value[:max_bytes_display],
                                     val_len=len(value))
    return value


format_str = '({group:04x}, {elem:04x}): {vr} {value}' 
with dicomfile(filename) as f:
    for data_elem in f:
        tag, vr, length, value, value_tell = data_elem
        vr_rep = vr
        if vr is None:
            vr_rep = "  "
        group, elem = tag
        value = val_repr(data_elem[3])
        print(format_str.format(group=group, elem=elem, vr=vr_rep, value=value))